<?php
namespace User\Form;

use Zend\Form\Form;

class RegisterForm extends Form
{
	public function __construct($name = null)
	{
		parent::__construct("Register");
		 
		$this->setAttribute('method', 'post');
		 
		$this->add(array(
				'name' => 'id',
				'attributes' => array(
					'type'  => 'hidden',
				),
		));
		 
		$this->add(array(
				'name' => 'username',
				'attributes' => array(
					'type'  => 'text',
					'required' => true,
				),
				'options' => array(
					'label' => 'Username',
				),
		));
		
		$this->add(array(
				'type' => '\Zend\Form\Element\Password',
				'name' => 'password',
				'attributes' => array(
					'required' => true,
				),
				'options' => array(
						'label' => 'Password',
				),
		));
		
		$this->add(array(
				'name' => 'first_name',
				'attributes' => array(
					'type'  => 'text',
				),
				'options' => array(
					'label' => 'First Name',
				),
		));
		
		$this->add(array(
				'name' => 'middle_name',
				'attributes' => array(
					'type'  => 'text',
				),
				'options' => array(
					'label' => 'Middle Name',
				),
		));
		
		$this->add(array(
				'name' => 'last_name',
				'attributes' => array(
					'type'  => 'text',
				),
				'options' => array(
					'label' => 'Last Name',
				),
		));
 
		$this->add(array(
				'type' => 'Zend\Form\Element\Email',
				'name' => 'email',
				'options' => array(
					'label' => 'Email'
				),
				'attributes' => array(
						'required' => false,
						),
				
		));

		$this->add(array(
				'type' => 'Zend\Form\Element\Date',
				'name' => 'dob',
				'options' => array(
					'label' => 'Date Of Birth'
				),
				'attributes' => array(
						'required' => false,
						),
		));
		 
		$this->add(array(
				'name' => 'phone',
				'attributes'=>array(
					'type'=>'text'
				),
				'options' => array(
					'label' => 'Phone',
				),
		));
		
		$this->add(array(
				'name' => 'avatar',
				'attributes'=>array(
					'type'=>'text'
				),
				'options' => array(
					'label' => 'Avatar',
				),
		));

		 
		$this->add(array(
				'name' => 'submit',
				'attributes' => array(
					'type'  => 'submit',
					'value' => 'Register',
					'id' => 'submitbutton',
				),
		));
	}
	 
	public function populateValues($data)
	{
		foreach($data as $key=>$row)
		{
			if (is_array(@json_decode($row))){
				$data[$key] =   new \ArrayObject(\Zend\Json\Json::decode($row), \ArrayObject::ARRAY_AS_PROPS);
			}
		}
		 
		parent::populateValues($data);
	}
}